<!DOCTYPE html>
<html xmlns:th="http://www.springframework.org/schema/mvc">
    <head>
        <meta charset="utf-8">
        <title>Layui</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <link rel="stylesheet" href="/static/layui/css/layui.css" media="all">
    </head>
    <body>
        <div class="layui-fluid" style="margin-top: 5px">
            <div class="layui-card">
                <div class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="navigation-form">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">类型</label>
                            <div class="layui-input-block">
                                <select name="modelId">
                                    <option value="" selected="selected">全部</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">网站名</label>
                            <div class="layui-input-block">
                                <input type="text" class="layui-input" name="linkName">
                            </div>
                        </div>
                        <div class="layui-inline searchBut">
                            <button class="layui-btn" lay-submit lay-filter="navigation-search">
                                查询
                            </button>
                            <button type="reset" class="layui-btn layui-btn-primary" id="resetBtn">重置</button>
                        </div>
                    </div>
                </div>
                <div class="layui-card-body">
                    <table class="layui-hide" id="navigation-table" lay-filter="navigation-table"></table>
                </div>
            </div>
        </div>
        <script type="text/html" id="barDemo">
            <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
            <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="visitUrl">访问</a>
        </script>
        <script src="/static/layui/layui.js" charset="utf-8"></script>
        <!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->

        <script th:inline="none">
            layui.use(['table', 'element', 'form'], function () {
                var table = layui.table;
                var element = layui.element;
                var form = layui.form;

                table.render({
                    elem: '#navigation-table',
                    url: '/rest/navigation/listTable',
                    defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                        title: '提示',
                        layEvent: '',
                        icon: 'layui-icon-tips'
                    }],
                    title: '用户数据表',
                    cols: [[
                        {type: 'checkbox', fixed: 'left'},
                        {
                            field: 'id',
                            title: '编号',
                            sort: true,
                            align: 'center',
                        },
                        {
                            field: 'modelName',
                            title: '模块名',
                            align: 'center',

                        },
                        {
                            field: 'linkName',
                            title: '网站',
                            align: 'center',

                        },

                        {
                            field: 'creatUser',
                            title: '创建人',
                            align: 'center',

                        },
                        {
                            field: 'clickCount',
                            title: '点击数',
                            align: 'center',

                        },
                        {
                            field: 'logUrl',
                            title: 'LOGO',
                            event: 'showLog',
                            style: 'cursor: pointer',
                            align: 'center',
                            templet: function (d) {
                                if (d.logoUrl != '') {
                                    return "<img style='height: 100%' src='" + d.logoUrl + "'></img>";
                                } else {
                                    return "";
                                }
                            },
                        },
                        {
                            fixed: 'right',
                            title: '操作',
                            toolbar: '#barDemo',
                        }
                    ]],
                    page: true,
                    limit: 10,
                    limits: [10, 15, 20, 25, 30],
                    text: "对不起，加载出现异常！",
                });

                //监听行工具事件
                table.on('tool(navigation-table)', function (obj) {
                    var data = obj.data;
                    if (obj.event === 'del') {
                        layer.confirm('真的删除行么', function (index) {
                            obj.del();
                            layer.close(index);
                        });
                    } else if (obj.event === 'edit') {
                        layer.prompt({
                            formType: 2
                            , value: data.linkUrl
                        }, function (value, index) {
                            obj.update({
                                email: value
                            });
                            layer.close(index);
                        });
                    } else if (obj.event === 'visitUrl') {
                        window.open(data.linkUrl, "_blank");
                    } else if (obj.event === 'showLog') {
                        if (data.logoUrl != '') {
                            layer.photos({
                                photos: {"data": [{"src": data.logoUrl}]}
                                , anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
                            });
                        }
                    }
                });

                form.render(null, 'navigation-form');
                //监听搜索
                form.on('submit(navigation-search)', function (data) {
                    var field = data.field;
                    //执行重载
                    table.reload('navigation-table', {
                        where: field, page: {
                            curr: 1
                        }
                    })
                });

            });

        </script>

    </body>
</html>